//
// Created by Administrator on 2023/7/29.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int minimumSum(int num) {
        vector<int> vc;
        while (num) {
            vc.push_back(num % 10);
            num /= 10;
        }
        sort(vc.begin(), vc.end());
        return vc[0] * 10 + vc[1] * 10 + vc[2] + vc[3];
    }
};
class Solution2 {
public:
    int minimumSum(int num) {
        string n = to_string(num);
        int ans = 0;
        sort(n.begin(),n.end());
        ans = (n[0]-'0')*10 + n[3]-'0' + (n[1]-'0')*10 + n[2]-'0';
        return ans;
    }
};

int main() {
    Solution s;
    cout << s.minimumSum(2932) << endl;
    cout << s.minimumSum(4009) << endl;
}